<?php
/**
 * Index.php
 * Niushop商城系统 - 团队十年电商经验汇集巨献!
 * =========================================================
 * Copy right 2015-2025 广西软甲士网络科技有限公司, 保留所有权利。
 * ----------------------------------------------
 * 官方网址: https://www.niushop.com
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
 * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
 * =========================================================
 * @author : niuteam
 * @date : 2015.1.17
 * @version : v1.0.0.0
 */

namespace addon\notes\api\controller;

use addon\notes\model\Group;
use app\api\controller\BaseApi;
use addon\notes\model\Notes as NotesModel;

class Notes extends BaseApi
{

    /**
     *  获取笔记分组
     */
    public function group()
    {
        $model = new Group();
        $list  = $model->getNotesGroupList([['site_id', '=', $this->site_id]], 'group_id,group_name,notes_num,release_num', 'sort asc');
        return $this->response($list);
    }

    /**
     * 获取文章列表
     */
    public function lists()
    {
        $page      = isset($this->params['page']) ? $this->params['page'] : 1;
        $page_size = isset($this->params['page_size']) ? $this->params['page_size'] : PAGE_LIST_ROWS;
        $group_id  = isset($this->params['group_id']) ? $this->params['group_id'] : '';

        $condition[] = ['pn.site_id', '=', $this->site_id];
        if ($group_id) {
            $condition[] = ['pn.group_id', '=', $group_id];
        }
        $note_model = new NotesModel();
        $list       = $note_model->getNotesPageList($condition, $page, $page_size);

        return $this->response($list);
    }

    /**
     * 文章详情
     */
    public function detail()
    {
        $note_id = isset($this->params['note_id']) ? $this->params['note_id'] : '';
        if (empty($note_id)) {
            return $this->response($this->error('', 'REQUEST_NOTE_ID'));
        }
        $condition = [
            ['site_id', '=', $this->site_id],
            ['note_id', '=', $note_id]
        ];

        $note_model = new NotesModel();
        $info       = $note_model->getNotesDetailInfo($condition, '*', 2);

        return $this->response($info);
    }


}